﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
//using System.Windows.Forms;
using InkFx.WinControl.Utils;

namespace InkFx.WinControl.Core
{
    /// <summary>
    /// 表示 边框的 四个边界的偏移量 (一般用于 图片切割裁剪时, 确定图片的边框区, 内部区)
    /// </summary>
    public struct BorderOffset
    {
        public int Top;
        public int Bottom;
        public int Left;
        public int Right;

        public static readonly BorderOffset Empty = new BorderOffset(0, 0, 0, 0);

        public bool IsEmpty
        {
            get { return Top == 0 && Bottom == 0 && Left == 0 && Right == 0; }
        }


        public BorderOffset(int top, int bottom, int left, int right)
        {
            this.Top = top;
            this.Bottom = bottom;
            this.Left = left;
            this.Right = right;
        }
        public BorderOffset(string str)
        {
            string[] split = (str ?? string.Empty).Split(new[] {',', '|'}, StringSplitOptions.None);
            this.Top = split.Length >= 1 ? Tools.ToInt(split[0], 0) : 0;
            this.Bottom = split.Length >= 2 ? Tools.ToInt(split[1], 0) : 0;
            this.Left = split.Length >= 3 ? Tools.ToInt(split[2], 0) : 0;
            this.Right = split.Length >= 4 ? Tools.ToInt(split[3], 0) : 0;
        }


        public Rectangle ToRectangle()
        {
            return new Rectangle(Left, Top, (Right - Left), (Bottom - Top));
        }
        public override string ToString()
        {
            string str = string.Format("{0}, {1}, {2}, {3}", this.Top, this.Bottom, this.Left, this.Right);
            return str;
        }

    }


    /// <summary>
    /// 窗体非客户区 各种尺寸属性 
    /// </summary>
    public struct SkinFormOffset
    {
        /// <summary>
        /// 窗体非客户区 标题栏+上边框高度
        /// </summary>
        public int CaptionAndTopSize
        {
            get { return CaptionSize + TopSize; }
        }

        /// <summary>
        /// 窗体非客户区 标题栏高度
        /// </summary>
        public int CaptionSize;

        /// <summary>
        /// 窗体非客户区 顶部高度
        /// </summary>
        public int TopSize;
        /// <summary>
        /// 窗体非客户区 底部高度
        /// </summary>
        public int BottomSize;
        /// <summary>
        /// 窗体非客户区 左边宽度
        /// </summary>
        public int LeftSize;
        /// <summary>
        /// 窗体非客户区 右边宽度
        /// </summary>
        public int RightSize;

        /// <summary>
        /// 窗体非客户区 可以拖动改变窗体尺寸的 边框厚度(光标 在这个 厚度内，会变成 尺寸修改光标 - 本属性与UI显示无关)
        /// </summary>
        public int Border;



        /// <summary>
        /// 当前结构体 数据为空
        /// </summary>
        public bool IsEmpty
        {
            get { return CaptionSize == 0 && TopSize == 0 && BottomSize == 0 && LeftSize == 0 && RightSize == 0 && Border == 0; }
        }

        public SkinFormOffset(int captionHeight, int topSize, int bottomSize, int leftSize, int rightSize, int border)
        {
            this.CaptionSize = captionHeight;
            this.TopSize = topSize;
            this.BottomSize = bottomSize;
            this.LeftSize = leftSize;
            this.RightSize = rightSize;
            this.Border = border;
        }

        /// <summary>
        /// 所有属性 全部为 0
        /// </summary>
        public static SkinFormOffset Empty = new SkinFormOffset(0, 0, 0, 0, 0, 0);


        /// <summary>
        /// 按照系统风格 得到的 非客户区尺寸
        /// </summary>
        public static SkinFormOffset CreateBySystemInformation(System.Windows.Forms.FormBorderStyle style)
        {
            Size borderSize = GetBorderSizeBySystemInformation(style);
            int captionHeight = GetCaptionHeightBySystemInformation(style);

            SkinFormOffset offset = new SkinFormOffset();
            offset.CaptionSize = captionHeight;
            offset.TopSize = borderSize.Height;
            offset.BottomSize = borderSize.Height;
            offset.LeftSize = borderSize.Width;
            offset.RightSize = borderSize.Width;
            offset.Border = borderSize.Width;

            return offset;
        }
        public static Size GetBorderSizeBySystemInformation(System.Windows.Forms.FormBorderStyle style)
        {
            Size borderSize;

            switch (style)
            {
                case System.Windows.Forms.FormBorderStyle.None:
                    borderSize = Size.Empty;
                    break;
                case System.Windows.Forms.FormBorderStyle.Fixed3D:
                    borderSize = System.Windows.Forms.SystemInformation.FixedFrameBorderSize;
                    break;
                case System.Windows.Forms.FormBorderStyle.FixedDialog:
                    borderSize = System.Windows.Forms.SystemInformation.FixedFrameBorderSize;
                    break;
                case System.Windows.Forms.FormBorderStyle.FixedSingle:
                    borderSize = System.Windows.Forms.SystemInformation.FixedFrameBorderSize;
                    break;
                case System.Windows.Forms.FormBorderStyle.Sizable:
                    borderSize = System.Windows.Forms.SystemInformation.FrameBorderSize;
                    break;
                case System.Windows.Forms.FormBorderStyle.SizableToolWindow:
                    borderSize = System.Windows.Forms.SystemInformation.FrameBorderSize;
                    break;
                case System.Windows.Forms.FormBorderStyle.FixedToolWindow:
                    borderSize = System.Windows.Forms.SystemInformation.FixedFrameBorderSize;
                    break;
                default:
                    borderSize = System.Windows.Forms.SystemInformation.BorderSize;
                    break;
            }

            return borderSize;
        }
        public static int GetCaptionHeightBySystemInformation(System.Windows.Forms.FormBorderStyle style)
        {
            int captionHeight;

            switch (style)
            {
                case System.Windows.Forms.FormBorderStyle.None:
                    captionHeight = 0;
                    break;
                case System.Windows.Forms.FormBorderStyle.Fixed3D:
                    captionHeight = System.Windows.Forms.SystemInformation.CaptionHeight;
                    break;
                case System.Windows.Forms.FormBorderStyle.FixedDialog:
                    captionHeight = System.Windows.Forms.SystemInformation.CaptionHeight;
                    break;
                case System.Windows.Forms.FormBorderStyle.FixedSingle:
                    captionHeight = System.Windows.Forms.SystemInformation.CaptionHeight;
                    break;
                case System.Windows.Forms.FormBorderStyle.Sizable:
                    captionHeight = System.Windows.Forms.SystemInformation.CaptionHeight;
                    break;
                case System.Windows.Forms.FormBorderStyle.SizableToolWindow:
                    captionHeight = System.Windows.Forms.SystemInformation.ToolWindowCaptionHeight;
                    break;
                case System.Windows.Forms.FormBorderStyle.FixedToolWindow:
                    captionHeight = System.Windows.Forms.SystemInformation.ToolWindowCaptionHeight;
                    break;
                default:
                    captionHeight = System.Windows.Forms.SystemInformation.CaptionHeight;
                    break;
            }

            return captionHeight;
        }
    }


}
